<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>短路运算</title>
</head>
<body>
    
    <script>
        

        /* // 判断  通过短路运算去判断  优雅的代替 -> if 
        +function () {
            const a = {
                "1": ["success","successPage"],
                "2": ["fail","failPage"],
                "error": ["error","errorPage"]
            };
            let action = (statusCode)=>{
                let whichItem = a[statusCode] || a['error'];
                console.log(`最终状态码是 - ${whichItem[0]}`);
                console.log(`准备跳转页面 - ${whichItem[1]}`);
            };
            action("1");
  
        } ();
        

        // 短路运算 代替if 

        + function () {

            let a = false;

            function fn () {
                console.log('this is a function');
            }

            a && fn ();

        } (); 


        // 函数的默认传参

        + function () {
            function fn (a,b="aaa") {
                console.log(a,b);
            }
            console.log(fn("what","bbb"));
        } ();

        // 合并两个数组

        + function () {

            let a = [1,2,3];
            let b= [4,5,6];
            console.log(a.concat(b));
            
            Array.prototype.push.apply(a,b);
            console.log(a);

        } ();
 */



    -function () {
        let f = function () {
            console.log('this is function');
        }

        let flag = false;

        flag || f();
    } ();


    </script>
</body>
</html>